package br.com.locasis.utilitarios;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

public class UtilProperties {

	private static final String NAME_PROPERTIES = "/deploy/documents.properties";
	public static final String PROPERTY_CAMINHO_FOTOS = "caminho_fotos";
	public static final String PROPERTY_CAMINHO_DOCUMENtOS = "caminho_documentos";
	
	public static String getValue(String key){
		try {
			Properties prop = new Properties();
			String caminhoProp = System.getProperty("jboss.server.home.dir");
			prop.load(new FileInputStream(new File(caminhoProp+NAME_PROPERTIES)));
			return prop.getProperty(key);
		} catch (IOException e) {
		}
		return null;
	}
	
	public static Properties getProperties(){
		try {
			Properties prop = new Properties();
			String caminhoProp = System.getProperty("jboss.server.home.dir");
			prop.load(new FileInputStream(new File(caminhoProp+NAME_PROPERTIES)));
			return prop;
		} catch (IOException e) {
			Properties prop = new Properties();
			return prop;
		}
	}
	
	public static void saveProperties(Properties properties){
		try {
			String caminhoProp = System.getProperty("jboss.server.home.dir");
			File file = new File(caminhoProp+NAME_PROPERTIES);
			FileOutputStream fileOut = new FileOutputStream(file);
			properties.store(fileOut, null);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
